package com.axend.aerosense.base.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModel;

import com.axend.aerosense.base.R;

/**
 * 带标题栏的fragment
 * 使用时请在布局xml中添加一下代码：
 * <include
 *      layout="@layout/base_layout_title_bar"/>
 *
 * @author ChenHongWei
 * @date :2020/12/25 16:09
 */

public abstract class MvvmBaseTitleFragment<V extends ViewDataBinding, VM extends ViewModel>
        extends MvvmBaseFragment<V , VM>{

    private TitleBar titleBar;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View view = super.onCreateView(inflater, container, savedInstanceState);
        titleBar = new TitleBar(view);
        setTitleBar(titleBar);
        return view;
    }



    /**
     * 配置titleBar
     * @param titleBar
     */
    protected abstract void setTitleBar(TitleBar titleBar);

    protected class TitleBar {

        public ImageView backImage;
        public TextView title;
        public ImageView rightImage;
        public TextView rightText;
        public TextView leftText;

        public ConstraintLayout baseLayout;
        private View view;

        public TitleBar(View view) {
            this.view = view;
            init();
        }

        private void init(){
            backImage = view.findViewById(R.id.room_iv_back);
            title = view.findViewById(R.id.room_iv_title);
            rightImage = view.findViewById(R.id.base_titlebar_right_image);
            rightText = view.findViewById(R.id.base_titlebar_right_text);
            leftText = view.findViewById(R.id.base_left_text);
            baseLayout = view.findViewById(R.id.base_layout);
        }

    }
}
